package com.gagakuai.bpm.service.camunda.impl;



import com.gagakuai.bpm.dao.mapper.camunda.SyncUserInfoMapper;
import com.gagakuai.bpm.domian.dto.scheduleTask.BPMUserVo;
import com.gagakuai.bpm.service.camunda.SyncUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
@Slf4j
public class SyncUserInfoServiceImpl implements SyncUserInfoService {

    @Resource
    private SyncUserInfoMapper syncUserInfoMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateUserInfo(BPMUserVo bpmUserVo) {
        int count = syncUserInfoMapper.updateUser(String.valueOf(bpmUserVo.getUserId()), bpmUserVo.getUsername());
        if(count < 1){
            return count;
        }

        count = syncUserInfoMapper.updateDept(bpmUserVo.getDeptInfo());
        if(count < 1){
            return count;
        }

        syncUserInfoMapper.deleteShip(String.valueOf(bpmUserVo.getUserId()), bpmUserVo.getDeptInfo());
        count = syncUserInfoMapper.insertShip(String.valueOf(bpmUserVo.getUserId()), bpmUserVo.getDeptInfo());

        return count;
    }
}
